﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    OpenPublisherPopup
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%Html.RenderPartial("_PopupPublisher"); %>
    <script type="text/javascript" charset="utf-8">
        function SearchPublisherName() {
            removeAllInLeft();
            var PublisherName = $("#txtPublisherName").val();
            var All = $("#AllPublisherList option");
            var FinalLeft = $("#LeftPublisherList");
            var numberAll = parseInt(All.length);
            for (var i = 0; i < numberAll; i++) {
                var content = All[i].innerText;
                if (content == undefined) {
                    content = All[i].textContent
                }
                if (content.toLowerCase().indexOf(PublisherName.toLowerCase()) != -1) {
                    FinalLeft.append('<option value=' + All[i].getAttribute('value') + '>' + content + '</option>');
                }
            }
        }
        function removeAllInLeft() {
            var Left = $("#LeftPublisherList option");
            Left.remove();
        }
        function AddPublisher() {
            var PublisherName = $("#txtPublisherName").val();
            var href = "/Publisher/DoCreatePublisher";
            $.post(href, { PublisherName: PublisherName },
            function (data) {
                if (data != "0") {
                    AddPublisherSuccess(data, PublisherName);
                }
            });
        }
        function AddPublisherSuccess(Id, Name) {
         
            //sau khi add author thanh cong thì add thang zo trong leftdiv và hiddendiv
            var Left = $("#LeftPublisherList");
            Left.append('<option value=' + Id + '>' + Name + '</option>');
            var All = $("#AllPublisherList");
            All.append('<option value=' + Id + '>' + Name + '</option>');
        }

        $('#LeftPublisherList').dblclick(function () {
            SavePublisher();
        });

        function LeftToRight() {
            var Left = $("#LeftPublisherList option:selected");
            var Right = $("#RightPublisherList option");
            var FinalRight = $("#RightPublisherList");
            var numberSelected = parseInt(Left.length);
            var NumberRowInRight = parseInt(Right.length);
            for (var i = 0; i < numberSelected; i++) {
                var duplicate = 0;
                for (var j = 0; j < NumberRowInRight; j++) {
                    if (Right[j].getAttribute("value") == Left[i].getAttribute("value")) {
                        duplicate = 1;
                    }
                }
                if (duplicate == 0) {
                    var content = Left[i].innerText;
                    if (content == undefined) {
                        content = Left[i].textContent
                    }

                    FinalRight.append('<option value=' + Left[i].getAttribute('value') + '>' + content + '</option>');
                }
            }
        }
        function RemoveFromRight() {
            var Right = $("#RightPublisherList option:selected");
            var numberSelected = parseInt(Right.length);
            for (var i = 0; i < numberSelected; i++) {
                $("#RightPublisherList option[value=" + Right[i].getAttribute('value') + "]").replaceWith("");
            }
        }
        function SavePublisher() {
            //step 1: get Publisher in Left Div

            var Publisher = "";
            var Left = $("#LeftPublisherList option:selected");
            var numberSelected = parseInt(Left.length);
            for (var i = 0; i < numberSelected; i++) {
                var content = Left[i].innerText;
                if (content == undefined) {
                    content = Left[i].textContent
                }
                Publisher += "," + Left[i].getAttribute('value');
                Publisher += "!" + content;
            }

            window.opener.loadDivPublisher(Publisher);
            window.close();


        }

    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Navigation" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MenuLeft" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Toolbar" runat="server">
</asp:Content>
